package cn.wolfcode.trip.admin.controller;


import cn.wolfcode.trip.admin.utils.UploadUtil;
import cn.wolfcode.trip.base.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@Controller

public class ImageController {



    @RequestMapping("/uploadImage")
    @ResponseBody
    public Object updateImg(MultipartFile upload){
        Map<String,Object> map = new HashMap<String, Object>();
        try {
            String imagePath = UploadUtil.upload(upload, UploadUtil.IMG_BASE_PATH+"/upload");
            map.put("url",imagePath);
            map.put("uploaded",1);

        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> map1= new HashMap<String,Object>();
            map1.put("message",e.getMessage());
            map.put("uploaded",0);
            map.put("error",map1);
        }
        return map;
    }

}
